package com.wty.gw.util;

public class ResponseData<T> {
    private String result;
    private boolean success;
    private String msg;
    private long elapsedMilliseconds;
    private T data;
    private ResponseMetaData metaData;

    public ResponseData() {
        this.result = ErrorCode.SUCCESS_CODE;
        this.msg = ErrorCode.MSG.get(ErrorCode.SUCCESS_CODE);
    }

    public ResponseData(T data) {
        this.result = ErrorCode.SUCCESS_CODE;
        this.msg = ErrorCode.MSG.get(ErrorCode.SUCCESS_CODE);
        this.data = data;
    }

    public ResponseData(T data,String message) {
        this.result = ErrorCode.SUCCESS_CODE;
        this.msg = message;
        this.data = data;
    }

    public ResponseData(String errorCode) {
        this.result = errorCode;
        this.msg = ErrorCode.MSG.get(errorCode);
    }

    public ResponseData(String errorCode, String errorMsg) {
        this.result = errorCode;
        this.msg = errorMsg;
    }

    public ResponseData(String errorCode, String errorMsg, long elapsedMilliseconds) {
        this.result = errorCode;
        this.msg = errorMsg;
        this.elapsedMilliseconds = elapsedMilliseconds;
    }


    public static ResponseData success(String errorMsg) {
        ResponseData responseData = new ResponseData();
        responseData.success = true;
        responseData.msg = errorMsg;
        responseData.metaData = new ResponseMetaData();
        return responseData;
    }


    public static ResponseData success(String errorMsg,Object data) {
        ResponseData responseData = new ResponseData();
        responseData.success = true;
        responseData.msg = errorMsg;
        responseData.metaData = new ResponseMetaData();
        responseData.data = data;
        return responseData;
    }


    public static ResponseData fail(String errorMsg) {
        ResponseData responseData = new ResponseData();
        responseData.success = false;
        responseData.msg = errorMsg;
        responseData.metaData = new ResponseMetaData();
        return responseData;
    }

    public static ResponseData fail(String errorMsg,Object data) {
        ResponseData responseData = new ResponseData();
        responseData.success = false;
        responseData.msg = errorMsg;
        responseData.metaData = new ResponseMetaData();
        responseData.data = data;
        return responseData;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getErrors() {
        return msg;
    }

    public void setErrors(String errors) {
        this.msg = errors;
    }

    public long getElapsedMilliseconds() {
        return elapsedMilliseconds;
    }

    public void setElapsedMilliseconds(long elapsedMilliseconds) {
        this.elapsedMilliseconds = elapsedMilliseconds;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ResponseMetaData getMetaData() {
        return metaData;
    }

    public void setMetaData(ResponseMetaData metaData) {
        this.metaData = metaData;
    }
}
